#列表
list1 = []
list2 = list()
list3 = [1,2,3,4,5]
print(list3)
for i in list3:
    print(i,end=' ')
    '''
    [1, 2, 3, 4, 5]
    1
    2
    3
    4
    5
    1
    5
    [1, 2, 3]
    [3, 4, 5]
    [1, 3, 5]
    '''
print(list3[0])
print(list3[-1])
print(list3[:3])
print(list3[2:])
print(list3[::2])
print(list3[::-1]) # 倒序 [5, 4, 3, 2, 1]
#添加元素
list3.append(6)
print(list3)
list3.insert(0,0)
print(list3)
list3.extend([7,8])
print(list3)

# print(list3[100])#IndexError: list index out of range
list4 = [11,5,33,22,66,1,9]
# list4.sort()
# print(list4)
# list4.sort(reverse=True)
# print(list4)
#  list4.sort()
#  list4.reverse()
#  print(list4)

#排序 不改变原列表
list4_new = sorted(list4)
print(list4)
print(list4_new)

#删除元素
print(list3)
list3.pop()
print(list3)
list3.pop(2)#2是下标
print(list3)
# list3.remove(55)#5是元素 ValueError: list.remove(x): x not in list
list3.remove(5)
print(list3)
# list3.clear()
# print(list3)

#修改元素
list3[0] = 100

#列表推导式
list5 = [i for i in list4 if i % 2 == 0]
print(list5)

#元组
tuple1 = ()
tuple2 = tuple()
tuple3 = (1,2,3,4,5)
print(tuple3)
for i in tuple3:
    print(i,end=' ')

print(tuple3[0])
print(tuple3[-1])
print(tuple3[1:4])
print(tuple3[::3])
print(tuple3[::2])

#集合
set1 = set([1,2,3,4,5,3,7,4,1])
print(set1)
set1.pop()
print(set1)
set1.remove(5)
print(set1)
set1.discard(3)
print(set1)

#字典
dict0 = {}
dict1 = dict()
dict2 = {'name':'张三','age':18,'sex':'男'}
print(dict2)
print(dict2['name'])
print(dict2['age'])
# for key, value in dict2.items():
#     print(key,value)
#
# for key, value in dict2.keys():
#     print(key)
print(dict2.get('id','没有相关数据'))
print(dict2.get('id2'))

dict2['id'] = 100
print(dict2)
dict2.update({'id':102,'sex':'女'})
print(dict2)
dict2.update({'phone':'12345678901','email':'<EMAIL>'})
print(dict2)

#删除字典元素
dict2.pop('id')
print(dict2)
dict2.clear()
print(dict2)

list8 = [1,2,3]
list9 = [4,5,6]
print(list8+list9)

print("*"*10)
print(list8*3)

tuple4 = (1,2,3)
print(tuple4*3)
print(tuple4+tuple4)

print(1 in list8)
print(111 in list8)
print(1 not in list8)
print(111 not in list8)

